package com.yiwei.zhh.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.ItemAdapter;
import com.yiwei.zhh.model.MyCertificationModel;
import com.yiwei.zhh.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

public class MyIdentityAdapter extends ItemAdapter<MyCertificationModel.Data.Basic, MyIdentityAdapter.AlipayUserViewHolder> {


    private final int px30;
    private final int px26;
    private Context context;

    public MyIdentityAdapter(Context context) {
        super(context);
        this.context = context;
        px30 = context.getResources().getDimensionPixelSize(R.dimen.x30);
        px26 = context.getResources().getDimensionPixelSize(R.dimen.x26);
    }


    @Override
    public AlipayUserViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new AlipayUserViewHolder(inflate(R.layout.item_identity, parent));
    }

    //    private int resId[] = {R.mipmap.img_identity_qq, R.mipmap.img_identity_jingdong, R.mipmap.img_identity_taobao, R.mipmap.img_identity_email, R.mipmap.img_identity_weixin};

    @Override
    public void onBindViewHolder(AlipayUserViewHolder holder, int position) {
        MyCertificationModel.Data.Basic item = getItem(position);

        switch (item.getRemark()) {
            case "taobao":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_taobao);
                break;
            case "jd":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_jingdong);
                break;
            case "weixin":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_weixin);
                break;
            case "qq":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_qq);
                break;
            case "email":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_email);
                break;
            case "linkedin":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_link);
                break;
            case "housefund":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_gongjijin);
                break;
            case "socialsecurity":
                holder.imgIcon.setImageResource(R.mipmap.img_identity_shebao);
                break;
            default:
                holder.imgIcon.setImageResource(R.mipmap.img_identity_taobao);
        }

        Spanned yudiString = Spans.with(context).font(item.getName(), px30, 0xff616185).
                p().
                font("积分+" + item.getRewards(), px26, 0xffff7a31).
                build();
        holder.editName.setText(yudiString);


        if (!TextUtils.isEmpty(item.getIscert())) {
            if (item.getIscert().equals("0")) {
                holder.txtQqStatus.setText("去认证");
                holder.txtQqStatus.setBackgroundResource(R.drawable.bg_identity_false);
            } else if (item.getIscert().equals("1")) {
                holder.txtQqStatus.setText("已认证");
                holder.txtQqStatus.setBackgroundResource(R.drawable.bg_identity_true);
            } else if (item.getIscert().equals("2")) {
                holder.txtQqStatus.setText("认证中");
                holder.txtQqStatus.setBackgroundResource(R.drawable.bg_identity_img);
            }
        }


//        switch (item.getIscert()) {
////            0失败 1成功 2认证中
//            case "0":

//                break;
//            case "1":

//                break;
//            case "2":

//                break;
//        }
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (OnIdentityClick != null) {
                    OnIdentityClick.onClick(item.getRemark(), item.getIscert());
                }
            }
        });
    }

    public interface OnIdentityClick {
        void onClick(String remark, String iscret);
    }

    private OnIdentityClick OnIdentityClick;

    public void setonIdentityListener(OnIdentityClick OnIdentityClick) {
        this.OnIdentityClick = OnIdentityClick;
    }

    class AlipayUserViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.edit_name)
        TextView editName;
        @BindView(R.id.txt_qq_status)
        TextView txtQqStatus;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        private AlipayUserViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
